define(function(require){
	var main =require('/static/main.js');
	var m = new main();
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		_init:function(){
		    this.getlist();
			this.bindEvent();
		},
		bindEvent:function(){
			
		},
		getlist:function(){
	        var param = {};
	        var sort = 0;
	        var table1 = $('#datatable').dataTable({
	        	'ordering':false,
	        	"serverSide": true,
	        	"searching":false,
	        	'bLengthChange': false,
	        	"scrollX": true,
	        	ajax: function (data, callback, settings) {
	                param.PageSize = data.length;
	                param.start = data.start;
	                param.PageNo = (data.start / data.length)+1;
	                $.ajax({
	                    type: "POST",
	                    url: "/drainage/turnplate-list",
	                    cache: false,  
	                    data: param, 
	                    dataType: "json",
	                    success: function (result) {
                    	    var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            callback(returnData);
	                    }
	                });
	            },
				"aoColumns":[
					{
						"mDataProp": 'ActWheellId',
						render:function(data){
							sort ++;
                    		return sort;
                    	}
					}, 
					{
			            "mDataProp": "ActWheellId",
			            "sClass": "option_btn",
			            "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			            	// console.log(arguments);
			                $(nTd).html('<div data-toggle="modal" data-target="#con-close-modal" style="display: inline-block;">\
                                                  <a href="/drainage/turnplatecreate?id='+sData+'"><span class="btn_edit" >编辑</span></a>\
                                                  <span class="btn_del" id='+sData+'>删除</span>\
                                                  <a href="/drainage/turnplategiftlist?id='+sData+'"  ><span class="btn_flow" style="margin-right:11px;">活动奖品管理</span></a>\
                                                  <a href="/drainage/turnplatetracking?id='+sData+'"><span class="btn_flow" >活动报名跟踪</span></a>\
                                                </div>');

			            }
			        },
					// {
					// 	"mDataProp": 'TitleSrc',
					// 	"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
					// 		$(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;max-height:70px;">')
			  //           }
					// },
					{
						"mDataProp": 'CoverSrc',
						"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
							$(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;max-height:70px;">')
			            }
					},
					{
                    	"mDataProp": 'ActName',
                   	}, 
                    {
                    	"mDataProp": 'Comment',
                    	"sClass": "avtivedes ",
                   	}, 
                   	{
                    	"mDataProp": 'ActCnt',
                   	},
                   	{
                    	"mDataProp": 'PlayCnt',
                   	},
                   	// {
                    // 	"mDataProp": 'DeliveryType',
                    // 	render:function(data){
                    // 		if(data == 300){
                    // 			return '线上物流发货（实物产品）'
                    // 		}else if(data == 200){
                    // 			return '线下门店自提（实物产品）'
                    // 		}else{
                    // 			return '系统自动处理（虚拟产品）'
                    // 		}
                    // 	}
                   	// },
                   	{
                    	"mDataProp": 'ReceiveAdd',
                   	},
                   	{
                    	"mDataProp": 'NoticeTel',
                   	},
                   	{
                    	"mDataProp": 'Hotline',
                   	},

                   	{
                    	"mDataProp": 'QRCode',
                    	"sClass": "show_QRCode",
                    	"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
							$(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;height:100px;">')
			            }
                   	},
                   	{
                    	"mDataProp": 'IsOpen',
                    	render:function(data){
                    		return data ? '开启' : '未开启'
                    	}
                   	},
                    {
                    	"mDataProp": 'StartTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '';
                    		}
                    	}
                	},
                	{
                    	"mDataProp": 'EndTime',
                    	render:function(data){
                    		if(data){
                    			return m.formatTimeAll2(data)
                    		}else{
                    			return '';
                    		}
                    	}
                	},
                	{
                    	"mDataProp": 'ShareSrc',
                    	"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
							$(nTd).html('<img src="'+sData+'" onerror="this.src=\'/modules/img/default.jpg\'" style="width:100px;max-height:70px;">')
			            }
                   	},

				],
	        }).api();
			// 点击搜索
	        $('#btnSearch').click(function(){
	        	param.ActName = $('.ActName').val();
	        	if($('.IsOpen option:selected').val() != 0){
	        		param.IsOpen = $('.IsOpen option:selected').val();
	        	}else{
	        		param.IsOpen = ''
	        	}
	        	param.StartTime = $('.StartTime').val()
	        	param.EndTime = $('.EndTime').val()
	        	sort = 0;
                table1.ajax.reload();
	        })
	        // 点击重置按钮
	        $('#btnRefresh').click(function(){
	        	$('.IsOpen option').each(function(){
					if($(this).val() == 0){
						$(this).attr('selected',true);
					}else{
						$(this).attr('selected',false);
					}
				})
	        	$('.ActName').val('');
	        	$('.StartTime').val('');
	        	$('.EndTime').val('');
	        })
	        // 点击删除
	        $(document).on('click','.btn_del',function(){
	        	var id = $(this).attr('id');
	        	layer.confirm('是否删除该活动？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
				  	$.ajax({
	                    type: "POST",
	                    url:'/drainage/turnplate-del',
	                    data:{ActWheellId:id},
	                    dataType: "json",
	                    success: function (ret) {
	                	  	if(ret.IsBizSuccess){
				                layer.msg('删除成功');
				                sort = 0;
				                table1.ajax.reload();
	                	  	}else{
	                	  		layer.msg(ret.ErrMsg);
	                	  		return false;
	                	  	}
	                    }
	                });
				});
	        })
		},

	}
	var a = new Cont();

})